(function() {
	"use strict";
	var app = angular.module("admin.login", ['ngCookies']);
	// 控制器
	app.controller('loginController', function($scope,$http,$cookies, $location,$rootScope) {
		var parent = $scope.$parent; 
		$scope.admin ={account:$cookies.get("account"),password:$cookies.get("password")};
		$scope.login = function(form){
				form.$setSubmitted(true);
				if(!$scope.form.$valid){
					return;
				}
	            //先清空密码 防止下去自动登陆
			    $scope.admin.error = "";
	            $scope.admin.loginMessage = "";
	            $http({
	                url:"/adminUser/login",
	                data:$scope.admin,
	                method:"POST"
	            }).success(function(data){
	                if(data.success){
	                    $cookies.put("account",$scope.admin.account);
	                    $cookies.put("password",$scope.admin.password);
	                    location.assign("/index.html");
	                }else{
	                    $scope.admin.error = data.error;
	                }
	            })
	        }
		document.onkeydown  = function(event){
		  if(event.keyCode  ==  13)   { 
			  $scope.login($scope.form);
		  } 
		}; 
	});
})();